package tech.xiaozai.rbac.security;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-09-23 10:28
 *
 *  用户对象,安全框架用
 */
@ToString
@Accessors(chain = true)
public class MyUserDetails implements UserDetails {

    @Setter
    @Getter
    private Long id;
    @Setter
    private String username;
    @Setter
    private String password;
    @Setter
    private Collection<GrantedAuthority> authorities;
    @Setter
    private Byte state;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return state==1;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return state==1;
    }
}
